<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<div class="layui-form hisi-search">
    <form action="{:url()}" method="get" id="hisi-table-search">

        <div class="layui-form-item">
            <label class="layui-form-label">调出仓库</label>
            <div class="layui-input-inline">
                <select name="a_warehouse" class="layui-input field-a_warehouse" lay-verify="required" lay-search="">
                  <option value="">直接选择或搜索选择</option>
                  {volist name="wares" id='vo'}
                  <option value="{$vo.id}">{$vo.name}</option>
                  {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">调入仓库</label>
            <div class="layui-input-inline">
                <select name="b_warehouse" class="layui-input field-b_warehouse" lay-verify="required" lay-search="">
                  <option value="">直接选择或搜索选择</option>
                  {volist name="$wares" id='vo'}
                  <option value="{$vo.id}">{$vo.name}</option>
                  {/volist}
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">状态</label>
            <div class="layui-input-inline">
                <select name="status" class="layui-input field-status" lay-verify="required" lay-search="">
                    <option value="">直接选择或搜索选择</option>
                    <option value="1">待审核</option>
                    <option value="2">通过</option>
                    <option value="3">不通过</option>
                </select>
            </div>
          </div>
        <div class="layui-form-item">
          <label class="layui-form-label">开始时间</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input field-start" id="start" name="start" placeholder="yyyy-MM-dd">
          </div>
        </div>
        <div class="layui-form-item">
          <label class="layui-form-label">结束时间</label>
          <div class="layui-input-inline">
            <input type="text" class="layui-input field-end" id="end" name="end" placeholder="yyyy-MM-dd">
          </div>
        </div>
        <input type="hidden" name="state" value="1">
        <div class="layui-form-item hisi-search-btn">

            <div class="layui-input-inline">
                <button type="submit" class="layui-btn layui-btn-normal layui-icon layui-icon-search">执行</button>
                <button type="button" class="layui-btn layui-btn-warm layui-icon layui-icon-download-circle export">导出</button>
            </div>
        </div>
    </form>
</div>

<table id="dataTable"></table>

<script type="text/html" id="statusTpl">
    <input type="checkbox" name="status" value="{{ d.status }}" lay-skin="switch" lay-filter="switchStatus" lay-text="正常|关闭" {{ d.status == 1 ? 'checked' : '' }} data-href="{:url('status')}?id={{ d.id }}">
</script>
<script type="text/html" title="操作按钮模板" id="buttonTpl">
    {{# if(d.status != 2){  }}
    <a href="{:url('edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1300px', height: '600px', title: '修改'}">修改</a>
     {{# } }}

    <a href="{:url('look')}?id={{ d.id }}&type=1" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1300px', height: '600px', title: '查看详情'}">详情</a>
    {{# if(d.status == 1 && {$shop_id} == d.b_shop){  }}

    <a href="{:url('check')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1200px', height: '600px', title: '审核'}">审核</a>
    {{# } }}
    <a href="{:url('edit')}?id={{ d.id }}&xx=2" class="layui-btn layui-btn-xs layui-btn-normal " target='_blank'>打印</a>
    <!-- <a href="{:url('del')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a> -->
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('add')}" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '1300px', height: '600px', title: '添加'}">&nbsp;添加</a>
</script>
<script type="text/javascript">
    layui.use(['table','laydate','excel'], function() {
        var table = layui.table;
        var laydate = layui.laydate;

//日期范围
laydate.render({
elem: '#start'
});
laydate.render({
elem: '#end'
});
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {type:'checkbox'}
                ,{field: 'id',width:70, title: 'ID'}
                ,{field: 'sn', title: '订单编号'}
                ,{field: 'a_shop_name', title: '调出门店'}
                ,{field: 'a_warehouse_name', title: '调出仓库'}
                ,{field: 'b_shop_name', title: '调入门店'}
                ,{field: 'b_warehouse_name', title: '调入仓库'}
                ,{field: 'status', title: '状态', templet:function(d){
                    switch(d.status){
                        case 1:
                            var str = '待审核';
                            break;
                        case 2:
                            var str = '通过';
                            break;
                        case 3:
                            var str = '不通过';
                            break;
                    }
                    return str;
                }}
                ,{field: 'bak', title: '备注'}
                ,{field: 'createtime', title: '创建时间',sort:true}
                ,{title: '操作', width: 250, templet: '#buttonTpl'}
            ]]

        });



        var excel = layui.excel;
          $(document).on('click','.export',function(){
              var form = $('#hisi-table-search').serializeArray();
              var where = new Array();
              form.push({name:'operation',value:2});
              $.ajax({
                 url: '{:url()}',
                 data:form,
                 dataType: 'json',
                 success: function(res) {
                     // 假如返回的 res.data 是需要导出的列表数据
                     console.log(res.data);// [{name: 'wang', age: 18, sex: '男'}, {name: 'layui', age: 3, sex: '女'}]
                     // 1. 数组头部新增表头
                     // 'ID','项目名称','数量','金额','手工','结算方式','职位','提成比例','添加时间','订单编号','会员','门店','员工','提成金额'
                     res.data.unshift({
                        sn:'订单编号',
                        a_shop_name:'调出门店',
                        a_warehouse_name:'调出仓库',
                        b_shop_name:'调入门店',
                        b_warehouse_name:'调入仓库',
                        bak:'备注',
                        status:'状态',
                        createtime:'创建时间',
                        name:'产品名称',
                        supplier_text:'供应商',
                        specs:'规格',
                        unit_text:'单位',
                        num:'数量',
                        pbak:'产品备注',
                         });
                     // 2. 如果需要调整顺序，请执行梳理函数
                     var data = excel.filterExportData(res.data, [
                        'sn',
                        'a_shop_name',
                        'a_warehouse_name',
                        'b_shop_name',
                        'b_warehouse_name',
                        'bak',
                        'status',
                        'createtime',
                        'name',
                        'supplier_text',
                        'specs',
                        'unit_text',
                        'num',
                        'pbak',
                     ]);
                     // 3. 执行导出函数，系统会弹出弹框
                     excel.exportExcel({
                         sheet1: data
                     }, '调拨单.xlsx', 'xlsx');
                 }
             });
          })

    });
</script>
